import '../index.dart';

class WorkOrderItem extends StatefulWidget {
  WorkOrderItem(this.order) : super(key: ValueKey(order.id));

  final Order order;

  @override
  _WorkOrderItemState createState() => _WorkOrderItemState();
}

class _WorkOrderItemState extends State<WorkOrderItem> {
  @override
  Widget build(BuildContext context) {
    //工单状态 0已保存,1已发送,待确认,2,已确定，待处理，3，已处理，待终结，4已终结待归档,5已归档
    String orderStatusImg = "order_not_assigned";
    switch (widget.order.orderStatus) {
      case 0:
        orderStatusImg = "order_not_assigned";
        break;
      case 1:
        orderStatusImg = "order_not_confirmed";
        break;
      case 2:
        orderStatusImg = "order_pending";
        break;
      case 3:
        orderStatusImg = "order_not_end";
        break;
      case 4:
        orderStatusImg = "order_not_archived";
        break;
      case 5:
        orderStatusImg = "order_archived";
        break;
      default:
        break;
    }

    List<Widget> list = [];
    list.add(
      Expanded(
        child: Text(
          (widget.order.suppleMemo ?? "") +
              "-" +
              (widget.order.repairResourceName ?? ""),
          // overflow: TextOverflow.ellipsis,
          style: Theme.of(context).textTheme.titleMedium,
        ),
      ),
    );
    if ((widget.order.remainingTime ?? "").isNotEmpty) {
      list.add(
        Material(
          color: (widget.order.remainingTime ?? "").startsWith("超时")
              ? Theme.of(context).colorScheme.error
              : Theme.of(context).colorScheme.primary,
          // elevation: 1.0,
          // 阴影颜色
          borderRadius:
              const BorderRadius.only(bottomLeft: Radius.circular(12)),
          // type: MaterialType.button,
          child: Container(
              padding:
                  const EdgeInsets.only(top: 5, left: 10, right: 10, bottom: 5),
              child: Text(widget.order.remainingTime ?? "",
                  style: Theme.of(context)
                      .textTheme
                      .labelMedium
                      ?.copyWith(color: Colors.white))),
        ),
      );
    }

    // var subtitle;
    return InkWell(
      child: Padding(
        padding: const EdgeInsets.only(left: 16,top: 16,bottom: 16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: list,
            ),
            const SizedBox(height: 14),
            Padding(
              padding: const EdgeInsets.only(right: 16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(
                        widget.order.defectAddress ?? "",
                        style: Theme.of(context).textTheme.bodyMedium,
                      ),
                      const SizedBox(height: 14),
                      Row(
                        children: [
                          Text(
                            '出单人：',
                            style: Theme.of(context)
                                .textTheme
                                .bodyMedium
                                ?.copyWith(
                                    color: Theme.of(context)
                                        .colorScheme
                                        .onSecondary),
                          ),
                          Text(
                            widget.order.createUserName ?? "",
                            style: Theme.of(context)
                                .textTheme
                                .bodyMedium
                                ?.copyWith(
                                    color: Theme.of(context)
                                        .colorScheme
                                        .onPrimary),
                          ),
                        ],
                      ),
                      const SizedBox(height: 14),
                      Row(
                        children: [
                          Text(
                            '出单时间：',
                            style: Theme.of(context)
                                .textTheme
                                .bodyMedium
                                ?.copyWith(
                                    color: Theme.of(context)
                                        .colorScheme
                                        .onSecondary),
                          ),
                          Expanded(
                            child: Text(
                              widget.order.createTime ?? "",
                              style: Theme.of(context)
                                  .textTheme
                                  .bodyMedium
                                  ?.copyWith(
                                      color: Theme.of(context)
                                          .colorScheme
                                          .onPrimary),
                            ),
                          ),
                        ],
                      ),
                      const SizedBox(height: 14),
                      Row(
                        children: [
                          Text(
                            '计划完单时间：',
                            style: Theme.of(context)
                                .textTheme
                                .bodyMedium
                                ?.copyWith(
                                    color: Theme.of(context)
                                        .colorScheme
                                        .onSecondary),
                          ),
                          Expanded(
                            child: Text(
                              widget.order.planCompleteTime ?? "",
                              style: Theme.of(context)
                                  .textTheme
                                  .bodyMedium
                                  ?.copyWith(
                                      color: Theme.of(context)
                                          .colorScheme
                                          .onPrimary),
                            ),
                          ),
                        ],
                      ),
                      // RichText(
                      //   text: TextSpan(children: [
                      //     TextSpan(
                      //       text: '计划完单时间：',
                      //       style: Theme.of(context)
                      //           .textTheme
                      //           .bodyMedium
                      //           ?.copyWith(
                      //               color: Theme.of(context)
                      //                   .colorScheme
                      //                   .onSecondary),
                      //     ),
                      //     TextSpan(
                      //       text: (widget.order.planCompleteTime ?? ""),
                      //       style: Theme.of(context).textTheme.bodyMedium,
                      //     )
                      //   ]),
                      // ),
                      const SizedBox(height: 14),
                      Stack(
                        children: [
                          Align(
                            alignment: Alignment.centerLeft,
                            child: Text(
                              widget.order.orderUrgencyName ?? "",
                              style: Theme.of(context)
                                  .textTheme
                                  .bodyText2
                                  ?.copyWith(
                                    color: widget.order.orderUrgencyName == "维修"
                                        ? const Color(0xFF20AF8D)
                                        : Theme.of(context).colorScheme.error,
                                  ),
                            ),
                          ),
                          Align(
                            alignment: Alignment.centerRight,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                Image.asset(
                                  "images/$orderStatusImg.png",
                                  width: 18,
                                  height: 14,
                                ),
                                Text(
                                  widget.order.orderStatusDesc ?? "",
                                  style: Theme.of(context)
                                      .textTheme
                                      .bodyMedium
                                      ?.copyWith(
                                          color: Theme.of(context)
                                              .colorScheme
                                              .onPrimary),
                                ),
                              ],
                            ),

                            // RichText(
                            //   text: TextSpan(children: [
                            //     WidgetSpan(
                            //       //对齐方式
                            //       alignment: PlaceholderAlignment.middle,
                            //       //这里就是中间显示的图片了也可以是其他任意的 Widget
                            //       child: Image.asset(
                            //         "images/$orderStatusImg.png",
                            //         width: 18,
                            //         height: 14,
                            //       ),
                            //     ),
                            //     TextSpan(
                            //       text: (widget.order.orderStatusDesc ?? ""),
                            //       style: Theme.of(context).textTheme.bodyMedium,
                            //     )
                            //   ]),
                            // ),
                          ),
                        ],
                      )
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
      onTap: () => Navigator.of(context).push(MaterialPageRoute(
          settings: const RouteSettings(name: "WorkOrderDetails"),
          builder: (context) => WorkOrderDetailsPage(
                orderId: widget.order.id!,
              ))),
    );
  }
}
